<script lang="ts" setup>
import { computed } from 'vue'

interface SvgIconProps {
  prefix?: string
  name: string
  color?: string
  size?: string
  class?: string
}

const props = withDefaults(defineProps<SvgIconProps>(), {
  prefix: 'icon',
  color: '#333',
  size: '24',
  class: '',
})

const iconName = computed<string>(() => `#${props.prefix}-${props.name}`)
const svgClass = computed<string>(() => {
  return props.name ? `svg-icon icon-${props.name} ${props.class}` : `svg-icon ${props.class}`
})
</script>

<template>
  <svg :class="svgClass" v-bind="$attrs" :style="{ color, fontSize: size }" aria-hidden="true">
    <use :xlink:href="iconName" />
  </svg>
</template>

<style lang="less" scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: middle;
  fill: currentColor;
  overflow: hidden;
}
</style>
